<template>
    <div>
        <el-header >
            <el-button @click="add()">添加专业</el-button>
            <el-button @click="updateTea()">同步数据</el-button>
        </el-header>

        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    fixed
                    prop="id"
                    label="id"
                    width="150">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="名称"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="wxId"
                    label="微信id"
                    width="120">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <el-button @click="edit(scope.row)" type="text" size="small">修改</el-button>
                    <el-button @click="deleteCollege(scope.row)" type="text" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                background
                layout="prev, pager, next"
                page-size="2"
                :total="total"
                @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "QueryTMajor",
        created() {
            const  _this=this;
            axios.get("http://localhost:8181/teacher/searchMajor/1/8").then(function (resp) {
                _this.tableData=resp.data.content
                _this.total=resp.data.toTalElements
            })
        },
        data(){
            return{
                total:null,
                tableData:[
                    {
                        id:'',
                        name:'',
                        wxId:''
                    }
                ],
                loading: true

            };
        },
        methods:{

            updateTea(){
                const _this=this;
                axios.get('http://localhost:8181/teacher/createAllTeacherDepartment').then(function (resp) {
                    console.log(resp);
                    _this.$alert('部门同步成功','成功!',{
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: 'action: ${action}'
                            });
                        }
                    });
                })
            },
            edit(row) {
                this.$router.push({
                    path:'/UpdateTMajor',
                    query:{
                        id:row.id
                    }
                })
            },
            add(){
                this.$router.push({
                    path:'/AddTMajor'
                })
            },
            deleteCollege(row){
                const  _this=this
                axios.get("http://localhost:8181/teacher/deleteMajor/"+row.id).then(function (resp) {
                    if (resp.data==="删除成功"){
                        _this.$alert('部门: '+row.name+'删除成功','消息',{
                            confirmButtonText:'确定',
                            callback:action => {
                                window.location.reload()
                            }
                        });
                    }
                })
            },
            page(currentPage){
                const _this=this
                axios.get('http://localhost:8181/teacher/searchMajor/'+currentPage+'/8').then(function (resp) {
                    _this.tableData=resp.data.content
                    console.log(resp.data)
                    _this.total=resp.data.totalElements
                })
            }
        }
    }
</script>

<style scoped>

</style>
